/****************************************************************************
 * 2025.5 阿桑的笔记本
 ****************************************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using QFramework;

namespace QFramework.Example
{
	public partial class ExpRoot : UIElement,IController,ICanReadModels
	{
		private void Awake()
		{
            ReadModels();

        }

		protected override void OnBeforeDestroy()
		{
		}

        public IArchitecture GetArchitecture()
        {
			return Global.Interface;
        }

        public void ReadModels()
        {
            DataManager.Instance.playerModel.PlayerExp.RegisterWithInitValue(value =>
            {

                ExpValue.fillAmount = value / (float)DataManager.Instance.LevelUp();
                if (value>=DataManager.Instance.LevelUp())
                {
                    DataManager.Instance.playerModel.PlayerExp.Value -= DataManager.Instance.LevelUp();
                    DataManager.Instance.playerModel.PlayerLevel.Value++;
                }

            }).UnRegisterWhenGameObjectDestroyed(gameObject);


            DataManager.Instance.playerModel.PlayerLevel.RegisterWithInitValue(value =>
            {
                LevelText.text = "Level"+ value.ToString();

            }).UnRegisterWhenGameObjectDestroyed(gameObject);
        }
    }
}